package com.azdebugit.concurrent.lock;

import java.util.concurrent.locks.ReentrantLock;

public class ReentrantLockDemo implements Runnable{

    //Step1：

    public static ReentrantLock lock = new ReentrantLock();

    public static int i = 0;


    @Override
    public void run() {
        for (int j = 0; j < 10; j++) {
            lock.lock();
            //lock.lock();  可重入锁

            try {
                i++;
            }finally {
                lock.unlock();
                //lock.unlock();可重入锁
            }

        }
    }


    public static void main(String[] args) throws InterruptedException {
        ReentrantLockDemo reentrantLock = new ReentrantLockDemo();

        Thread thread = new Thread(reentrantLock);
        
        thread.start();
        thread.join();
        System.out.println(i);
    }
}
